package com.forsythia.sns;

import java.util.List;

import org.junit.Test;

import com.forsythia.sns.service.UserService;
import com.forsythia.sns.to.UserTO;

public class UserServiceTestCase extends BaseTestCase {

    @Test
    public void testCreateUserAccount() {
        UserTO user = new UserTO().setUserId(SequenceUUID.getInstance().getUUID()).setLoginName("LoginName").setEmail(
                "test@test.com").setPassword("Password").setUserName("User Name");
        user = userService.createUserAccount(user);
        assertTrue(user != null);

        List<UserTO> userList = userService.findByProperty("email", "test@test.com");
        assertTrue(userList != null && userList.size() != 0);
    }

    public void testIsLoginSuccess() {
        assertTrue(userService.isLoginSuccess("test@test.com", "Password"));
        assertTrue(userService.isLoginSuccess("LoginName", "Password"));
        
        assertFalse(userService.isLoginSuccess("test@test.com", "WrongPassword"));
        assertFalse(userService.isLoginSuccess("LoginName", "WrongPassword"));
        
        //assertFalse(userService.isLoginSuccess("test@test.com", ""));
        //assertFalse(userService.isLoginSuccess("", "WrongPassword"));
        
        assertException(userService, "isLoginSuccess", new Class[]{String.class, String.class}, new String[]{"", ""} );
    }

    protected void setUp() throws Exception {
        super.setUp();
        this.userService = (UserService) getApplicationContext().getBean("userService");
    }

    private UserService userService;

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
